# _*_ encoding: utf-8 _*_
from django.db import models

# Create your models here.
class Icecream(models.Model):
	name = models.CharField(max_length = 100)
	price = models.IntegerField()
	scoops_count = models.IntegerField()

	def __unicode__(self):
		return self.name

class Scoop(models.Model):
	name = models.CharField(max_length = 100)

	def __unicode__(self):
		return self.name


class Table(models.Model):
	is_free = models.BooleanField(verbose_name='is_free')
	def __unicode__(self):
		return str(self.id) + " " + ('reserved','free')[self.is_free]


class Order(models.Model):
    order_time = models.DateTimeField(auto_now = True)

    class Meta:
        ordering = ['order_time']

    def __unicode__(self):
        return str(self.order_time)
   
class OrderItem(models.Model):
    order = models.ForeignKey(Order)
    table = models.ForeignKey(Table)
    icecream = models.ForeignKey(Icecream)
    scoops = models.ManyToManyField(Scoop)

    def __unicode__(self):
		scoops_all = ""
		for obj in self.scoops.all():
			scoops_all += "+ " + obj.name + " "
		return "Table " + str(self.table) + " : " + str(self.icecream) + " " + str(scoops_all)
    
